package util;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class FileUtil {
	public static byte[] getPicture(File file) {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		InputStream in = null;
		try {
			in = new BufferedInputStream(new FileInputStream(file));
			byte[] buf = new byte[4096];
			while (true) {
				int readedBytes = in.read(buf);
				if (readedBytes == -1) {
					break;
				}
				out.write(buf, 0, readedBytes);
			}
		} catch (IOException ioe) {
		} finally {
			try {
				in.close();
			} catch (IOException e) {
			}
		}
		return out.toByteArray();
	}

	public static String getExtensaoArquivo(File file) {
		return file.getName().substring(file.getName().lastIndexOf("."));
	}

}
